﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrazyWorship1.PropertyHandler;
using System.Globalization;
using System.Windows.Media.Media3D;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows;


namespace CrazyWorship1.Assets
{
    class TiledBackgroundAsset:AssetBase
    {
        string _FileName;
        double _XScale,_YScale,_ZScale, _ZOffset;

        bool _Tiled;
        [DataAttribute("FileName", typeof(StringPropertyHandler),"TiledBackgroundAssetDefaultFileName")]
        public string FileName
        {
            get
            {
                return _FileName.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                _FileName = Convert.ToString(value, CultureInfo.InvariantCulture);
            }
        }
        [DataAttribute("IsTiled", typeof(BoolPropertyHandler), "TiledBackgroundAssetDefaultIsTiled")]
        public string IsTiled
        {
            get
            {
                return _Tiled.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                _Tiled = Convert.ToBoolean(value, CultureInfo.InvariantCulture);
            }
        }
        [DataAttribute("ZOffset", typeof(DoublePropertyHandler), "TiledBackgroundAssetDefaultZOffset")]
        public string ZOffset
        {
            get
            {
                return _ZOffset.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                _ZOffset = Convert.ToDouble(value, CultureInfo.InvariantCulture);
            }
        }
        [DataAttribute("XScale", typeof(DoublePropertyHandler), "TiledBackgroundAssetDefaultXScale")]
        public string XScale
        {
            get
            {
                return _XScale.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                _XScale = Convert.ToDouble(value, CultureInfo.InvariantCulture);
            }
        }
        [DataAttribute("YScale", typeof(DoublePropertyHandler), "TiledBackgroundAssetDefaultYScale")]
        public string YScale
        {
            get
            {
                return _YScale.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                _YScale = Convert.ToDouble(value, CultureInfo.InvariantCulture);
            }
        }
        [DataAttribute("ZScale", typeof(DoublePropertyHandler), "TiledBackgroundAssetDefaultZScale")]
        public string ZScale
        {
            get
            {
                return _ZScale.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                _ZScale = Convert.ToDouble(value, CultureInfo.InvariantCulture);
            }
        }
        public GeometryModel3D Model
        {
            get
            {
                return model;
            }
            
        }
        public ImageBrush Brush
        {
            get
            {
                return brush;
            }
        }
        GeometryModel3D model;
        ImageBrush brush;
        public override void Go()
        {
            model = ParentCreator.CreateEmptyPanel(ParentCreator.BackgroundModelGroup, new Point3D(0, 0, _ZOffset), new QuaternionRotation3D(), new Point3D(0, 0, 0),new Vector3D(_XScale,_YScale,_ZScale));
            brush = new ImageBrush();

            brush.ImageSource = new BitmapImage(new Uri(_FileName, UriKind.Relative));
            if (_Tiled)
            {
                brush.TileMode = TileMode.Tile;
                brush.Viewport = new Rect(0, 0, 0.25, 0.25);
            }
            model.Material = new DiffuseMaterial(brush);

        }
    }
}
